import React, { Fragment } from 'react'
import { View, StyleSheet } from 'react-native'
import { connect } from 'react-redux'
import { ScaleS, ScaleT } from 'src/utils/ScreenUtil'
import { UPDATE_USERINFO_ACTION } from '../../../store/actions/userinfo'
import BaseManager from 'src/pageP/base/base-manager'
import WorkExperienceCard from '../../../components/card-work-experience'
import CustomButton from '../../../components/button/CustomButton'
import { CommonToast } from '../../../utils/ToastUtil'

// 发送行为
const mapDispatchToProps = dispatch => ({
  updateUserInfo (payload) {
    dispatch(UPDATE_USERINFO_ACTION(payload))
  }
})

@connect(({ CMineCenterStore }) =>
  ({
    userArchiveWorkModels: CMineCenterStore.userArchiveWorkModels
  }), mapDispatchToProps
)

class CWorkExperience extends BaseManager {
  constructor (props) {
    super(props)
    this.titleText = '工作经验'
    this.completeText = '添加工作经历'
    this.showSaveBtn = false
  }

  childContentRender () {
    const { userArchiveWorkModels } = this.props
    return (
      <Fragment>
        {
          userArchiveWorkModels && userArchiveWorkModels.length > 0 && userArchiveWorkModels.map((item, index) => {
            return (
              <CustomButton onPress={this._workExperienceItemClick} params={{ item }} key={item.id}>
                <WorkExperienceCard style={styles.workExperienceItem} dataSource={item}/>
              </CustomButton>)
          })
        }
      </Fragment>
    )
  }

  _workExperienceItemClick = ({ item }) => {
    const { userArchiveWorkModels } = this.props
    this.props.navigation.navigate('CWorkExperienceManager', {
      workExperience: item,
      showDelete: userArchiveWorkModels.length > 1
    })
  }

  onComplete () {
    const { userArchiveWorkModels, navigation } = this.props
    if (userArchiveWorkModels.length >= 10) {
      CommonToast('教育信息最多只能添加10条')
    } else {
      navigation.navigate('CWorkExperienceManager')
    }
  }
}

export default CWorkExperience

const styles = StyleSheet.create({
  container: {
    flex: 1
  },
  workExperienceItem: {
    marginTop: ScaleS(20)
  }
})
